package com.suyl.annotationdemo.model.controller;

import com.suyl.annotationdemo.core.annotation.Person;
import com.suyl.annotationdemo.core.validator.PersonValidator;

/**
 * @author : suyl
 * @version : v1.0.0
 * @date : 2020/3/20 15:02
 * @descr : 测试注解Person
 */
@Person(validator = PersonValidator.class)
public class TestAnnotation {
    public static void main(String[] args) {
        Print(TestAnnotation.class);
        System.out.println(tableSizeFor((1 << 20) - 1));
        String regex = "ab{1,3}+bc";
        if ("abbc".matches(regex)) {
            System.out.println("matche");
        } else {
            System.out.println("no matche");
        }
    }

    public static void Print(Class zclass) {
        System.out.println(zclass.getName());

        Person person = (Person) zclass.getAnnotation(Person.class);
        if (person != null) {
            System.out.println("name=" + person.name() + ";age=" + person.age());
        } else {
            System.out.println("person unknown!!");
        }
    }

    /**
     * 寻找比cap大的最小的2的n次幂
     *
     * @param cap
     * @return
     */
    static final int tableSizeFor(int cap) {
        int n = cap - 1;
        n |= n >>> 1;
        n |= n >>> 2;
        n |= n >>> 4;
        n |= n >>> 8;
        n |= n >>> 16;
        return (n < 0) ? 1 : (n >= 1 << 30) ? 1 << 30 : n + 1;

    }
}
